﻿
@{
    ViewBag.Title = "部门管理";
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
}
<div class="layui-tab layui-tab-brief" lay-filter="user">
    <div class="layui-form layui-tab-content" id="LAY_ucm">
        <form action="">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="keyWord" class="layui-input" value="@ViewBag.Keyword" placeholder="请输入名称搜索">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn searchButton">搜索</button>
                    <a class="layui-btn" href="javascript:ShowPage('/Management/Department/Create','添加部门',3)">添加部门</a>
                    <a class="layui-btn" lay-href="/Management/Department/ShowTree">查看组织结构图</a>
                </div>
            </div>
        </form>
    </div>
    <table class="layui-table" style="float:left;" lay-data="{url:'/Management/Department/GetData', cellMinWidth: 80, page: true,limit:15}" id="resultList" lay-filter="resultList">
        <thead>
            <tr>
                <th lay-data="{field:'ID',align:'center',  width:80}">ID</th>
                <th lay-data="{ field: 'Name',edit: 'text'}">名称(双击修改名称)</th>
                <th lay-data="{field:'FullName', width:300}">完整路径</th>
                <th lay-data="{field:'PositionName', width:300}">管理岗位</th>
                <th lay-data="{width:60,field:'Sort',edit:'text',type:'mynumbers'}">排序</th>
                <th lay-data="{width:80,toolbar: '#status'}">状态</th>
                <th lay-data="{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}">操作</th>
            </tr>
        </thead>
    </table>
    <script type="text/html" id="status">
        {{# if(d.Status==-1){ }}
        已禁用
        {{# } else{ }}
        正常
        {{# } }}
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:setLeaderPositionID({{d.ID}})">设置部门负责岗位</a>
        {{# if(d.Status==-1){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:enabledItem({{d.ID}})">启用</a>
        {{# } else{ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:disEnabledItem({{d.ID}})">禁用</a>
        {{# } }}

    </script>

</div>
<script type="text/javascript">
    function disEnabledItem(id) {
        layer.confirm('您确认需要禁用该部门？<p style="color:red">禁用该部门同时会禁用其下属部门</p>', {
            btn: ['我要禁用', '不小心点错了'], title: '部门禁用确认' //按钮
        }, function () {
            var url = "/Management/Department/Delete?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.msg("部门禁用成功!");
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Msg);
                }
            });
        }, function () {

        });
    }

    function enabledItem(id) {
        layer.confirm('您确认启用当前部门吗？', {
            btn: ['我要启用', '不小心点错了'], title: '部门启用确认' //按钮
        }, function () {
            var url = "/Management/Department/Enabled?id=" + id;
            $.getJSON(url, function (data) {
                if (data.State === 200) {
                    layer.msg("部门启用成功!");
                    $(".layui-laypage-btn")[0].click();
                }
                else {
                    layer.msg(data.Message);
                }
            });
        }, function () {

        });
    }

    function setLeaderPositionID(id) {
        layer.open({
            type: 2,
            title: "设置部门负责岗位",
            shadeClose: false,
            shade: 0.3,
            area: ["800px","400px"],
            content: '/Management/Department/SetLeaderPositionID?id=' + id
        });
    }



    layui.use('table', function () {
        var table = layui.table;         
        table.on('edit(resultList)', function (obj) {
            if (obj.field === 'Name') {
                var url = "/Management/Department/SetName?id=" + obj.data.ID + "&name=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("部门名称修改成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Message);
                    }
                });
            }
            else if (obj.field === 'Sort') {
                var url = "/Management/Department/SetSort?id=" + obj.data.ID + "&sort=" + obj.value;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        layer.msg("排序修改成功", { time: 500 });
                    }
                    else {
                        layer.msg(data.Message);
                    }
                });
            }
        });

    });

</script>


